package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.dto.PutChallengeTable;
import com.atguigu.srb.core.pojo.dto.PutCooperationTable;
import com.atguigu.srb.core.pojo.entity.*;
import com.atguigu.srb.core.service.ApplyActService;
import com.atguigu.srb.core.service.ClubRegistrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "社长管理")
@CrossOrigin
@RestController
@RequestMapping("/admin/core/management")
@Slf4j
public class PresidentManagementController {


    @Resource
    private ApplyActService applyActService;
    @Resource
    private ClubRegistrationService clubRegistrationService;

    @ApiOperation("申请活动")
    @PostMapping("/applic")
    public R application(
            @ApiParam(value = "活动对象")
            @RequestBody CommunityActivities communityActivities
            ){


        boolean save = applyActService.save(communityActivities);
        if (save){
            return R.ok().message("申请成功");
        }else {
            return R.error().message("申请失败");
        }
    }


    @ApiOperation("更改社团信息")
    @PutMapping("/update")
    public R ClubInformation(
            @ApiParam(value = "社团信息")
            @RequestBody CommunityInformation communityInformation
            ){



    boolean result= clubRegistrationService.updatecommunityinformation(communityInformation);

    if(result){
        return R.ok().message("更新成功");
    }else {
        return  R.error().message("更新失败");
    }
      }

    @ApiOperation("查看报名表")
    @GetMapping("/agree/{id}")
    public R ClubRegistration(
            @ApiParam(value = "社团编号")
            @PathVariable String id
    ){
     List<ClubRegistration> registration  = clubRegistrationService.getByNumber(id);


     return  R.ok().data("list",registration);


    }
    @ApiOperation("增加成员")
    @PutMapping("/increase/{id}")
    public R Increasemembers(
            @ApiParam("社团报名id")
            @PathVariable int id
    ){
        ClubRegistration clubRegistration = clubRegistrationService.getById(id);
        clubRegistration.setExamineState("True");
        clubRegistrationService.updateById(clubRegistration);
         boolean result= applyActService.increasemember(clubRegistration);
         if(result){
             return R.ok().message("增加成员成功");
         }else
         {
             return R.error().message("增加成员失败");
         }


    }


    @ApiOperation("查看社团成员")
    @GetMapping("/number/{communitynumber}")
    public R communitynumber(
            @ApiParam(value = "社团编号")
            @PathVariable String communitynumber
    ){
        List<CommunityMemberInformation> communityMemberInformations  = applyActService.getByNumber(communitynumber);

        if(communityMemberInformations !=null){
              return  R.ok().data("list",communityMemberInformations).message("查询成功");

        }else {
            return R.error().message("查看成员失败");
        }
    }

    @ApiOperation("发起挑战")
    @PostMapping("/challenge")
    public R challenge(
            @ApiParam(value = "发起挑战的表")
            @RequestBody PutChallengeTable putChallengeTable
            ){

    Boolean result = applyActService.putchallenge(putChallengeTable);
    if (result){
        return R.ok().message("已发起挑战");
    }else {
        return R.error().message("发起挑战失败");
    }
    }

    @ApiOperation("查询本社团发出的挑战(社长版)")
    @GetMapping("/selectchallenge/{communitynumber}")
    public R selectchallenge(
            @ApiParam(value = "社团编号")
            @PathVariable String communitynumber
    ){
      List<ChallengeTable> challengeTables=applyActService.getchallengtable(communitynumber);
      if(challengeTables !=null){
          return R.ok().data("list",challengeTables).message("查询成功");
      }else {
          return R.ok().message("无挑战");
      }
    }
    @ApiOperation("查询挑战本社团的挑战")
    @GetMapping("/selectchall/{communitynumber}")
    public R selectchall(
            @ApiParam(value = "社团编号")
            @PathVariable String communitynumber
    ){
        List<ChallengeTable> challengeTables=applyActService.getchall(communitynumber);
        if(challengeTables !=null){
            return R.ok().data("list",challengeTables).message("查询成功");
        }else {
            return R.ok().message("无挑战");
        }
    }


    @ApiOperation("是否确认本挑战")
    @PutMapping("/confirmchallenge")
    public R Confirmchallenge(
            @ApiParam(value = "挑战id")
            @RequestParam int id,
            @ApiParam(value = "是否接接受（已接受，不接受）")
            @RequestParam String data
            ){
      Boolean result =  applyActService.confirmchallenge(id,data);
        if (result){
            return R.ok().message("操作成功");
        }else {
            return R.error().message("操作失败");
        }
    }

    @ApiOperation("设置挑战结果")
    @PutMapping("/challengeresult")
    public R ChallengeResult(
            @ApiParam(value = "挑战id")
            @RequestParam int id,
            @ApiParam(value = "结果(成功社团编号)")
            @RequestParam String data
    ){
        String result = String.valueOf(applyActService.challengeresutl(id,data));
        if (result!=null){
            return R.ok().data("communityname",result);
        }else {
            return R.error().message("设置失败");
        }
    }

    //发起合作
    @ApiOperation("发起合作")
    @PostMapping("/cooperation")
    public R cooperation(
            @ApiParam(value = "发起合作的表")
            @RequestBody PutCooperationTable putCooperationTable
            ){

        Boolean result = applyActService.putcooperation(putCooperationTable);
        if (result){
            return R.ok().message("已发起合作");
        }else {
            return R.error().message("发起合作失败");
        }
    }

    //查看本社团合作（社长版）
    @ApiOperation("查询本社团发出的合作(社长版)")
    @GetMapping("/selectcooperation/{communitynumber}")
    public R selectcooperation(
            @ApiParam(value = "社团编号")
            @PathVariable String communitynumber
    ){
        List<CooperationTable> challengeTables=applyActService.getcooperation(communitynumber);
        if(challengeTables !=null){
            return R.ok().data("list",challengeTables).message("查询成功");
        }else {
            return R.ok().message("无合作");
        }
    }
    @ApiOperation("查询与本社团合作的合作")
    @GetMapping("/selectcooper/{communitynumber}")
    public R selectcooper(
            @ApiParam(value = "社团编号")
            @PathVariable String communitynumber
    ){
        List<CooperationTable> challengeTables=applyActService.getcooper(communitynumber);
        if(challengeTables !=null){
            return R.ok().data("list",challengeTables).message("查询成功");
        }else {
            return R.ok().message("无合作");
        }
    }

    //是否合作
    @ApiOperation("是否确认本合作")
    @PutMapping("/confirmcooperation")
    public R Confirmcooperation(
            @ApiParam(value = "合作id")
            @RequestParam int id,
            @ApiParam(value = "是否接接受（已接受，不接受）")
            @RequestParam String data
    ){
        Boolean result =  applyActService.confirmcooperation(id,data);
        if (result){
            return R.ok().message("操作成功");
        }else {
            return R.error().message("操作失败");
        }
    }


}
